﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.LiveFX.ResourceModel;
using System.Net;

namespace Wintellect.LiveFx.Cloudboard
{
  internal static class MeshHelper
  {
    public static ResourceCollection<ContactResource> GetContactList(System.Net.NetworkCredential liveId)
    {
      if (liveId == null) throw new ArgumentNullException("liveId");

      String token = liveId.GetWindowsLiveAuthenticationToken();
      LiveFxClient cloudClient = new LiveFxClient(token);
      ServiceDocumentResource cloudServiceDocument = cloudClient.ReadServiceDocument();
      ResourceCollection<ContactResource> output = cloudServiceDocument.ReadContacts(cloudClient);
      return output;
    }

    /// <summary>
    /// The world's most primitive RTF detection algorithm
    /// </summary>
    /// <param name="text">A <see cref="System.String"/> containing the text to test.</param>
    /// <returns>A <see cref="System.Boolean"/> indicating whether the text appears to contain RTF content.</returns>
    public static bool IsTextRTF(String text)
    {
      bool output = false;
      
      if (!String.IsNullOrEmpty(text))
      {
        output = text.StartsWith("{\\rtf1");
      }

      return output;
    }
  }
}
